package com.chnagli06.method_more;

public class Recursion {
    public static void main(String[] args) {
        //求一百以内的和
        Recursion test = new Recursion();
        int n =100;
        System.out.println(test.getSum(n));//求和
        System.out.println(test.factrial(5));//阶乘
        System.out.println(test.fabonacci(10));//斐波那契数列
        System.out.println(test.hanot(2));//汉诺塔问题
    }
    //求和
    public  int  getSum(int n){
        if(n==1){
            return 1;
        }
        else {
            return getSum(n-1)+n;
        }
    }
    //阶乘
    public int factrial(int n){
        if(n==1){
            return 1;
        }
        else {
            return factrial(n-1)*n;
        }
    }
    //斐波那契
    public  int fabonacci(int n){
        if(n==1||n==2){
            return 1;
        }
        else {
            return fabonacci(n-1)+fabonacci(n-2);
        }

    }
    public int hanot(int n){
//        char a,b,c;
//        a='a';
//        b='b';
//        c='c';
        if(n==1){
            return 1;

        }else{
            return hanot(n-1)+hanot(n-1)+1;
        }
    }
}
